<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Album
 * @copyright  Copyright 2006-2010 Webligo Developments
 * @license    http://www.socialengine.net/license/
 * @version    $Id: view.tpl 9291 2011-09-21 02:38:15Z shaun $
 * @author     Sami
 */
?>
<script type="text/javascript">
en4.core.runonce.add(function() {
	$('frmEditDes').removeEvent('submit').addEvent('submit', function(e){
		e.stop();
		var form_values  = $('frmEditDes').toQueryString();
			form_values += '&format=json';
	    request = new Request.JSON({
	        url : en4.core.baseUrl + 'ialbum/album/quick-edit',
	        data : form_values,
	        onComplete: function(response) {
				if(response.status){
					$('description').show();$('frmEditDes').hide();
					$('desAlbum').set('html', response.description);
				}else{
					//alert show error
				}
	        }
	      });
	      request.send();	
	});
});
</script>
<div class="layout_middle ialbum">
<?php if($this->view_type != 'comment'):?>
	<?php if( $this->mine || $this->canEdit ): ?>
	  <script type="text/javascript">
	    var SortablesInstance;
	
	    en4.core.runonce.add(function() {
	      $$('.thumbs_nocaptions > li').addClass('sortable');
	      SortablesInstance = new Sortables($$('.thumbs_nocaptions'), {
	        clone: true,
	        constrain: true,
	        //handle: 'span',
	        onComplete: function(e) {
	          var ids = [];
	          $$('.thumbs_nocaptions > li').each(function(el) {
	            ids.push(el.get('id').match(/\d+/)[0]);
	          });
	          //console.log(ids);
	
	          // Send request
	          var url = '<?php echo $this->url(array('action' => 'order')) ?>';
	          var request = new Request.JSON({
	            'url' : url,
	            'data' : {
	              format : 'json',
	              order : ids
	            }
	          });
	          request.send();
	        }
	      });
	    });
	  </script>
	<?php endif ?>

  <ul class="thumbs thumbs_nocaptions ialbum">
    <?php foreach( $this->paginator as $photo ): ?>
      <li id="thumbs-photo-<?php echo $photo->photo_id ?>">
        <a  class="thumbs_photo ialbum_photo_lightbox" href="<?php echo $photo->getHref(); ?>">
          <span style="background-image: url(<?php echo $photo->getPhotoUrl('thumb.normal'); ?>);"></span>
        </a>
        <?php if($photo->comment_count):?>
        <div style="" class="RL">
        	<div class="SL">
        		<div class="UL"><?php echo $photo->comment_count?></div>
        		<div class="TL">
        		</div>
			</div>
			<div class="VL">
				<div class="XL"><?php echo $photo->comment_count?></div>
				<div class="WL">
				</div>
			</div>
		</div>
		<?php endif;?>
      </li>
      
    <?php endforeach;?>
  </ul>
  
 <?php else:?>
 	<div id="album_photos_pagelet">
	 	<ul id="commentViewList" class="uiList">
	 	<?php foreach( $this->paginator as $photo ): ?>
		 	<li class="xPhoto pvm uiListItem uiListLight uiListVerticalItemBorder">
		 		<div class="clearfix">
		 			<a href="<?php echo $photo->getHref();?>" class="lfloat ialbum_photo_lightbox">
		 				<span class="uiMediaThumb commentViewThumb uiMediaThumbMedium">
		 					<i style="background-image: url(<?php echo $photo->getPhotoUrl();?>); height: 320px;"></i>
		 				</span>
		 			</a>
		 		<div class="pll commentViewMetadata photoUfiContainer rfloat">
		 			<div id="photoSetCommentsCaption" class="photosPhotoCaption pbs">
		 				<span class="hasCaption"><br>
							<?php echo $photo->getDescription();?>
						</span>
		 			</div>
		 			<div id="photoSetCommentsTagList" class="photoTagList hidden_elem">
		 				<span class="photoTagListTag tagItem hidden_elem">
		 					
		 				</span>
		 			</div>
		 			<div class="photosPhotoFeedback">
		 				<?php 
							$api = Engine_Api::_()->getApi('Content', 'Ialbum');
								$api->setPhotoId($photo->getIdentity());
							echo $api->getWidgetCommentPhoto();
								 $api->clearLayout();
								 $api->setPhotoId(0);
							unset ($api);
						?>
		 			</div>
		 		</div>
		 	  </div>
		 	</li>
		 <?php endforeach;?>		
	 	</ul>
	 	<div class="bottomborder"></div>
	 </div>
 <?php endif;?>
  
  	<div class="des_album">  	  
		  <p id="description">
		  	<?php if( '' != trim($this->album->getDescription()) ): ?>
		  		<?php if( $this->mine || $this->canEdit ): ?>
			  		<a onclick="$('description').hide();$('frmEditDes').show();$('desAlbumValue').focus();" href="javascript:void(0);" class="rfloat mbs mls editIcon"></a>
			    <?php endif;?>
		  		<span id="desAlbum"><?php echo $this->album->getDescription() ?></span>
		    <?php else:?>
		    	<?php if( $this->mine || $this->canEdit ): ?>
		    		<a href="javascript:void(0);" onclick="$('description').hide();$('frmEditDes').show();$('desAlbumValue').focus();"><?php echo $this->translate('Add a description');?></a>		 		  		
		  		<?php endif;?>
		   <?php endif ?>
		  </p>
	<?php if( $this->mine || $this->canEdit ): ?>	  
	  <form style="display: none;" id="frmEditDes" name="frmEditDes" enctype="application/x-www-form-urlencoded" method="post">
	  		<textarea class="areaDes" name="description" id="desAlbumValue"><?php echo $this->album->getDescription();?></textarea>
	  		<div class="editActions">
				<button name="submit" type="submit"><?php echo $this->translate('Save changes')?></button>
				<button onclick="$('description').show();$('frmEditDes').hide();" name="cancel" type="button"><?php echo $this->translate('Cancel')?></button>
			</div>
			<input type="hidden" name="album_id" value="<?php echo $this->album->getIdentity();?>">
	  </form>
	  <?php endif;?>
	</div>
	 <br>
	

  <?php if( $this->paginator->count() > 0 ): ?>
    <?php echo $this->paginationControl($this->paginator); ?>
  <?php endif; ?>
  <!-- comment -->
</div>